/**
 * 
 */
package br.ufal.ic.sd.project.server.factory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import br.ufal.ic.sd.project.server.core.Server;
import br.ufal.ic.sd.project.server.exception.ServerException;
import br.ufal.ic.sd.project.server.servermode.MonoThreadService;
import br.ufal.ic.sd.project.server.servermode.MultiThreadService;
import br.ufal.ic.sd.project.server.util.Constants;

/**
 * @author keven andrade
 *
 */
public class RunModeFactory {
    
    public static Server getService() throws ServerException{
	
	Properties objProperties = new Properties();
	
	try {
	    objProperties.load(new FileInputStream(Constants.SERVER_PROPERTIES));
	} catch (FileNotFoundException e) {
	    throw new ServerException(e.getMessage());
	} catch (IOException e) {
	    throw new ServerException(e.getMessage());
	}
	
	if(objProperties.getProperty("mode").equals("monothread")){
	    
	    return new MonoThreadService(new Integer(objProperties.getProperty("port")), new String(objProperties.getProperty("repository")));
	    
	}else{
	    
	    return new MultiThreadService(new Integer(objProperties.getProperty("port")),new String(objProperties.getProperty("repository")));
	}
	
    }

}
